home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / a_man / cat7 / drain.z / drain
Encoding:
Text File  |  2002-10-03  |  7.1 KB  |  199 lines

  1.  
  2.  
  3.  
  4. DDDDRRRRAAAAIIIINNNN((((7777PPPP))))                                                            DDDDRRRRAAAAIIIINNNN((((7777PPPP))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      drain - capture unimplemented link-layer protocols
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      ####iiiinnnncccclllluuuuddddeeee <<<<ssssyyyyssss////ttttyyyyppppeeeessss....hhhh>>>>
  13.      ####iiiinnnncccclllluuuuddddeeee <<<<nnnneeeetttt////rrrraaaawwww....hhhh>>>>
  14.  
  15.      ssss ==== ssssoooocccckkkkeeeetttt((((PPPPFFFF____RRRRAAAAWWWW,,,, SSSSOOOOCCCCKKKK____RRRRAAAAWWWW,,,, RRRRAAAAWWWWPPPPRRRROOOOTTTTOOOO____DDDDRRRRAAAAIIIINNNN))));;;;
  16.  
  17. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  18.      The Drain protocol provides non-promiscuous capture of packets having
  19.      unimplemented link-layer protocol types, i.e., packets that the operating
  20.      system normally receives and drops ``down the drain''.  It treats packets
  21.      as datagrams containing a link-layer header followed by data.  Drain uses
  22.      the Raw address format, interpreting ports as link-layer type codes (in
  23.      host byte order) to match against unimplemented types in received
  24.      packets.  Multiple sockets may bind to the same port on a network
  25.      interface.
  26.  
  27.      Drain can map several link-layer type codes to a port.  There is one
  28.      type-to-port mapping for each network interface; it is initialized to map
  29.      zero to zero.  Call _i_o_c_t_l(2) with the SSSSIIIIOOOOCCCCDDDDRRRRAAAAIIIINNNNMMMMAAAAPPPP command and the
  30.      address of the following structure, declared in <_n_e_t/_r_a_w._h>, to set a
  31.      mapping:
  32.  
  33.           struct drainmap {
  34.                u_short   dm_minport;    /* lowest port in range */
  35.                u_short   dm_maxport;    /* and highest port */
  36.                u_short   dm_toport;     /* port mapped by range */
  37.           };
  38.  
  39.  
  40.      Drain input from Ethernet network interfaces is demultiplexed based on
  41.      the eeeetttthhhheeeerrrr____ttttyyyyppppeeee member of the eeeetttthhhheeeerrrr____hhhheeeeaaaaddddeeeerrrr structure, declared in
  42.      <_n_e_t_i_n_e_t/_i_f__e_t_h_e_r._h> and documented in _e_t_h_e_r_n_e_t(7).
  43.  
  44.      If the link-layer header size is not congruent with RRRRAAAAWWWW____AAAALLLLIIIIGGGGNNNNGGGGRRRRAAAAIIIINNNN, Drain
  45.      input prepends RRRRAAAAWWWW____HHHHDDDDRRRRPPPPAAAADDDD((((_h_d_r_s_i_z_e)))) bytes of padding to received packets.
  46.      Output on a Drain socket, using _w_r_i_t_e(2) or _s_e_n_d(2), takes a buffer
  47.      address pointing at the link-layer packet to be transmitted, not at any
  48.      prepended padding.
  49.  
  50. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  51.      To capture from an Ethernet network interface, first declare an input
  52.      buffer structure with the required header padding:
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. DDDDRRRRAAAAIIIINNNN((((7777PPPP))))                                                            DDDDRRRRAAAAIIIINNNN((((7777PPPP))))
  71.  
  72.  
  73.  
  74.           #include <sys/types.h>
  75.           #include <net/raw.h>
  76.           #include <netinet/if_ether.h>
  77.  
  78.           #define ETHERHDRPAD RAW_HDRPAD(sizeof(struct ether_header))
  79.  
  80.           struct etherpacket {
  81.                char           pad[ETHERHDRPAD];
  82.                struct ether_header ether;
  83.                char           data[ETHERMTU];
  84.           };
  85.  
  86.  
  87.      To capture all Reverse ARP (RARP) packets, create a Drain socket and bind
  88.      it to the RARP port on the primary network interface (error handling is
  89.      omitted for clarity):
  90.  
  91.           #define   ETHERTYPE_RARP 0x8035
  92.  
  93.           int s;
  94.           struct sockaddr_raw sr;
  95.  
  96.           s = socket(PF_RAW, SOCK_RAW, RAWPROTO_DRAIN);
  97.           sr.sr_family = AF_RAW;
  98.           sr.sr_port = ETHERTYPE_RARP;
  99.           bzero(sr.sr_ifname, sizeof sr.sr_ifname);
  100.           bind(s, &sr, sizeof sr);
  101.  
  102.  
  103.      Alternatively, to capture all Ethernet packets with IEEE 802.3
  104.      encapsulations, create and bind a socket to a port different from any
  105.      valid eeeetttthhhheeeerrrr____ttttyyyyppppeeee:
  106.  
  107.           #define   IEEE802_3PORT  1
  108.  
  109.           int s;
  110.           struct sockaddr_raw sr;
  111.  
  112.           s = socket(PF_RAW, SOCK_RAW, RAWPROTO_DRAIN);
  113.           sr.sr_family = AF_RAW;
  114.           sr.sr_port = IEEE802_3PORT;
  115.           bzero(sr.sr_ifname, sizeof sr.sr_ifname);
  116.           bind(s, &sr, sizeof sr);
  117.  
  118.  
  119.      Map all Ethernet types corresponding to packet lengths, as specified by
  120.      802.3, to the bound port:
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. DDDDRRRRAAAAIIIINNNN((((7777PPPP))))                                                            DDDDRRRRAAAAIIIINNNN((((7777PPPP))))
  137.  
  138.  
  139.  
  140.           struct drainmap map;
  141.  
  142.           map.dm_minport = 1;
  143.           map.dm_maxport = 1500;
  144.           map.dm_toport = IEEE802_3PORT;
  145.           ioctl(s, SIOCDRAINMAP, &map);
  146.  
  147.  
  148.      Before reading, it may be desirable to increase the Drain socket's
  149.      default receive buffer size.  The following code also shows how to
  150.      transmit a link-layer packet:
  151.  
  152.           struct etherpacket ep;
  153.           int cc = 10000;
  154.  
  155.           setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *) &cc, sizeof cc);
  156.           for (;;) {
  157.                cc = read(s, (char *) &ep, sizeof ep);
  158.                /* . . . */
  159.                write(s, (char *) &ep.ether, cc - sizeof ep.pad);
  160.           }
  161.  
  162.  
  163. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  164.      A socket operation may fail with one of the following errors returned:
  165.  
  166.      [EISCONN]      when trying to establish a connection on a socket which
  167.                     already has one, or when trying to send a datagram with
  168.                     the destination address specified and the socket is
  169.                     already connected;
  170.  
  171.      [ENOBUFS]      when the system runs out of memory for an internal data
  172.                     structure or a send or receive buffer.
  173.  
  174.      [EADDRINUSE]   when an attempt is made to create a socket with a port
  175.                     which has already been allocated;
  176.  
  177.      [EADDRNOTAVAIL]
  178.                     when an attempt is made to create a socket with a network
  179.                     address for which no network interface exists.
  180.  
  181.      [EOPNOTSUPP]    when an _i_o_c_t_l operation not supported by the Drain
  182.                      protocol is attempted.
  183.  
  184. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  185.      getsockopt(2), socket(2), intro(3), ethernet(7), raw(7F), snoop(7P)
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.